<template>
  <el-container class="main_con" >
   <ufrom @submit="saveData" ref="ufrom">

        <el-form size="medium" label-width="100px">
          <div class="setting_body_item">
            <div class="header">消费返积分</div>
            <div class="conetnt edit_con">
              <div class="edit_content">
                <el-form-item label="类型">
                  <el-radio-group v-model="obj.get_integral_type">
                    <el-radio :label="0">商品单独设置 </el-radio>
                    <el-radio :label="1">消费金额比例</el-radio>
                    <el-radio :label="2">购买数量</el-radio>
                  </el-radio-group>
                </el-form-item>
                <el-form-item v-if="obj.get_integral_type == 1">
                  <div class="fks">
                    返还比例：
                    <el-input v-model="obj.get_integral_ratio" style="width:280px;margin-right:10px;margin-left:10px;">
                      <template slot="prepend">
                        支付金额的
                      </template>
                      <template slot="append">
                        %
                      </template>
                    </el-input>
                  </div>
                </el-form-item>
                <el-form-item v-if="obj.get_integral_type == 2">
                  <div class="fks">
                    返还比例：
                    <el-input v-model="obj.get_integral_ratio" style="width:280px;margin-right:10px;margin-left:10px;">
                      <template slot="prepend">
                        每件商品
                      </template>
                      <template slot="append">
                        积分
                      </template>
                    </el-input>
                  </div>
                </el-form-item>
              </div>
            </div>
          </div>

        </el-form>
   </ufrom>
  </el-container>
</template>

<script>
import {getintegral, editintegral} from '@/api/mall/deduction';
export default {
  data() {
    return {
      isLoading: false,
      obj: {
        is_open: 0,
        deduction: 0
      }
    };
  },

  mounted() {
    this.getintegral();
  },
  methods: {
    //获取站点配置数据
    getintegral() {
      this.isLoading = true;
      getintegral({})
        .then(res => {
          if (res.msg) {
            let o = res.msg;
            if(o.get_integral_type==1){
              o.get_integral_ratio=o.get_integral_ratio*100
            }
            this.obj = res.msg;
          }
        })
        .catch(e => {
        });
    },
    //保存数据
    saveData() {
      let data = {
        deduction: this.obj.deduction,
        is_open: this.obj.is_open,
        get_integral_type:this.obj.get_integral_type
      };
      if(this.obj.get_integral_type==1){
        data.get_integral_ratio=this.obj.get_integral_ratio/100
      }else{
         data.get_integral_ratio=this.obj.get_integral_ratio
      }
      editintegral(data)
        .then(res => {
          this.$refs.ufrom.init()
          this.$message.success("修改成功")
          this.getintegral();
        })
        .catch(e => {
          this.$refs.ufrom.init()
        });
    }
  }
};
</script>
